package farmaciaweb.com.br.entity;

import java.io.Serializable;
import java.lang.String;
import java.util.Collection;

import javax.persistence.*;

import static javax.persistence.GenerationType.SEQUENCE;

/**
 * Entity implementation class for Entity: Substancia
 *
 */
@Entity
@NamedQueries(value = {
		@NamedQuery(name = "bd_farmaciaweb.consultaSubstancia", query = "SELECT s FROM Substancia s " +
																"where (s.descricao like :desc) " )})

public class Substancia implements Serializable{
  
	/**
	 * 
	 */
	private static final long serialVersionUID = 7480775699890243564L;

	@Id
	@Column(name = "idSubstancia")
	@GeneratedValue(strategy = SEQUENCE, generator = "subst_gen")
	@SequenceGenerator(name = "subst_gen", sequenceName = "subst_seq", allocationSize = 5)
	private int idSubstancia;
	
	@Column(nullable = false, length = 50)
	private String descricao;

	@OneToMany(mappedBy = "substancia")
	private Collection<Medicamento> medicamento;
	
	public Substancia() {
		super();
	}   
	public int getIdSubstancia() {
		return this.idSubstancia;
	}

	public void setIdSubstancia(int idSubstancia) {
		this.idSubstancia = idSubstancia;
	}   
	public String getDescricao() {
		return this.descricao;
	}

	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + idSubstancia;
		result = prime * result
				+ ((medicamento == null) ? 0 : medicamento.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Substancia other = (Substancia) obj;
		if (idSubstancia != other.idSubstancia)
			return false;
		if (medicamento == null) {
			if (other.medicamento != null)
				return false;
		} else if (!medicamento.equals(other.medicamento))
			return false;
		return true;
	}
	
	
   
	
}
